package virtorina.server.domain;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import virtorina.server.PMF;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class QuestionLabel implements Serializable {

	private static final long serialVersionUID = 1L;
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long ID;
	@Persistent
	private Long QuestionID;
	@Persistent
	private Long LabelID;

	public Long getID() {
		return ID;
	}

	public void setID(Long iD) {
		ID = iD;
	}

	public Long getQuestionID() {
		return QuestionID;
	}

	public void setQuestionID(Long questionID) {
		QuestionID = questionID;
	}

	public Long getLabelID() {
		return LabelID;
	}

	public void setLabelID(Long labelID) {
		LabelID = labelID;
	}

	public QuestionLabel(Long questionID, Long labelID) {
		super();
		QuestionID = questionID;
		LabelID = labelID;
	}

	public QuestionLabel() {
		super();
	}

	public static void saveLinks(LinkedList<QuestionLabel> ql) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		pm.makePersistentAll(ql);
		pm.close();
	}
	
	public static LinkedList<Long> getLabelsID(Long QuestionID){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query q = pm.newQuery("select from " + QuestionLabel.class.getName()
				+ " where QuestionID == qID");
		q.declareParameters("Long qID");
		List<QuestionLabel> answ = (List<QuestionLabel>) q.execute(QuestionID);
		LinkedList<Long> rslt = new LinkedList<Long>();
		for (QuestionLabel ql: answ){
			rslt.add(ql.getLabelID());
		}
		pm.close();
		return rslt;
	}
	
	

}
